#include "graphicsrectitem.h"
#include <QBrush>
#include "graphicstextitem.h"
#include <QtWidgets>
#include <QDebug>
#include "itemmimedata.h"
#include "times.h"
#include "dragdrop.h"

GraphicsRectItem::GraphicsRectItem(QGraphicsItem *parent)
	: QGraphicsRectItem(parent)
{
	int margain = 4;

	setRect(0,0,180,160);
	//setBrush( QBrush(QColor(255,0,0)));
	setFlags(QGraphicsItem::ItemIsMovable |
		QGraphicsItem::ItemIsSelectable);

	setAcceptDrops(true);

	mlabel = new GraphicsTextItem(this);
	mlabel->setPlainText(tr("this is a rect"));
	mlabel->setPos(margain,margain);

}

GraphicsRectItem::~GraphicsRectItem()
{

}

void GraphicsRectItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
	Times::outCurrentTime("textItem");
	//event->pos().
	qDebug() << "->GraphicsTextItem.mousePressEvent() enter."
		<<"("<<event->pos().x()<<","<<event->pos().y()<<")";
	QThread::usleep(1);

	if(gDragDrop->itemMousePressEvent(event, this))
		return;

	QGraphicsRectItem::mousePressEvent(event);
}
void GraphicsRectItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
	if( gDragDrop->itemMouseMoveEvent(event,this))
		return;

	QGraphicsRectItem::mouseMoveEvent(event);
}
// drag & drop;
void GraphicsRectItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
	qDebug("->GraphicsRectItem.dragEnterEvent().");
	gDragDrop->itemDragEnterEvent(event,this);
}
void GraphicsRectItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
	qDebug("->GraphicsRectItem.dragMoveEvent().");
	gDragDrop->itemDragMoveEvent(event,this);
}
void GraphicsRectItem::dropEvent(QGraphicsSceneDragDropEvent *event)
{
	qDebug("->GraphicsRectItem.dropEvent().");
	gDragDrop->itemDropEvent(event,this);
}